/*
 * Copyright (c) 2023, 2024,yzc.cn All rights reserved.
 *
 */
package com.by.mq.consumer;

import com.by.mapper.FinPlanDetailMapper;
import com.by.mapper.FinPlanMapper;
import com.by.pojo.FinPlan;
import com.by.pojo.FinPlanDetail;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: erp-cloud-api - FinPlanMQConsumer</p>
 * <p>Powered by yzc On 2024-01-16 11:06:20</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */
@Component
public class FinPlanMQConsumer {

    @Autowired
    FinPlanMapper finPlanMapper;

    @Autowired
    FinPlanDetailMapper finPlanDetailMapper;

    @RabbitListener(queues = {"finPlanQueue"})
    public void handlerFinPlan(HashMap<String,Object> map)  {
        FinPlan finPlan =new FinPlan();
        int sum = (Integer) map.get("batch");
        finPlan.setBatch(sum);
        finPlan.setName(map.get("name").toString());
        finPlan.setContractCode(map.get("contractCode").toString());
        finPlanMapper.insert(finPlan);
        for (int i = 1; i <= sum; i++) {
            FinPlanDetail detail = new FinPlanDetail();
            detail.setPid(finPlan.getId());
            detail.setBatch(i);
            detail.setDay(45);
            finPlanDetailMapper.insert(detail);
        }




    }


}
